package com.example.demo1108.demo1;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.start();

        Thread.sleep(1000);
        System.out.println(" 止损");
        t.setFlag(false);
    }

}
class T extends Thread{
    private  volatile  boolean flag=true;
    public void setFlag(boolean flag){
        this.flag=flag;
    }
    @Override
    public void run(){
        System.out.println("flag = " + flag);
        while (flag){

        }
    }
}
